﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReadyApps.Wiki;

namespace ReadyApps.Data.Wiki
{
    // TODO: Unit test RolePrivileges
    /// <summary>
    /// Represents a single role and its associated privileges.
    /// </summary>
    /// <seealso cref="PermissionSet"/>
    /// <seealso cref="EffectivePermissions"/>
    [Serializable]
    public class RolePrivileges
    {
        #region Properties

        /// <summary>
        /// Gets the name of the role associated with the set of privileges.
        /// </summary>
        public string RoleName { get; private set; }

        /// <summary>
        /// Gets the <see cref="EffectivePermissions"/> associated with the role.
        /// </summary>
        public EffectivePermissions Privileges { get; private set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Creates a new <see cref="RolePrivileges"/> object for the given role
        /// and default privileges.
        /// </summary>
        /// <param name="roleName">The role name.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="roleName"/>
        /// parameter was null or empty.</exception>
        public RolePrivileges(string roleName)
            : this(roleName, new EffectivePermissions()) { }

        /// <summary>
        /// Creates a new <see cref="RolePrivileges"/> object for the given role
        /// name and its associated privileges.
        /// </summary>
        /// <param name="roleName">The role name.</param>
        /// <param name="privileges">The privileges associated with the role.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="roleName"/>
        /// parameter was null or empty.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="privileges"/>
        /// parameter was null.</exception>
        public RolePrivileges(string roleName, EffectivePermissions privileges)
        {
            if (string.IsNullOrEmpty(roleName))
            {
                throw new ArgumentNullException("roleName");
            }
            if (privileges == null)
            {
                throw new ArgumentNullException("privileges");
            }
            RoleName = roleName;
            Privileges = privileges;
        }

        #endregion
    }
}
